<?php

class Notification_model extends CI_Model {

	function __construct() {
		parent::__construct();
	}

	function insert_notification($notification) {
		$sql = "INSERT INTO notification (fb_id, message, date_created) VALUES (?, ?, NOW())";		
		$result = $this->db->query($sql, array($notification['fb_id'], $notification['message']));
		
		return $result;
	}

	function get_notifications($fb_id, $p='') {
		
		if ($p)
			$page = (($p - 1) * 2);
		else
			$page = '';
		$sql = "SELECT * FROM notification WHERE fb_id = ? ";
		if ($page)
			$sql .= " LIMIT " . $page . ", 2";
		$query = $this->db->query($sql, $fb_id);
		
		$data = array();
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row)
				$data[] = $row;
		}
		return $data;
	}
	
	function get_notification_count($fb_id)
	{
		$sql = "SELECT * FROM notification WHERE fb_id = ?";
		$query = $this->db->query($sql, $fb_id);
		
		return $query->num_rows();
	}
	
	function new_notification_count($fb_id) {
		$sql = "SELECT * FROM notification WHERE fb_id = ? AND is_new = 1";
		$query = $this->db->query($sql, $fb_id);
		
		return $query->num_rows();
	}
}
?>